//
//  MyViewController.m
//  VideoPic
//
//  Created by apple on 16/3/21.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "MyViewController.h"
#import "YMMyListType1TableViewCell.h"
#import "YMMyListType2TableViewCell.h"
#import "YMMyListType3TableViewCell.h"



@interface MyViewController () <UITableViewDelegate, UITableViewDataSource>
{
    UIImageView *navBarHairlineImageView;
}

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UIView *loginView;
@property (nonatomic, strong) UIView *logoutView;

@end

@implementation MyViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self hidenNavigationBar];    
    [self createSubViews];
}

- (void)hidenNavigationBar {
    [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsCompact];
    if ([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]){
        NSArray *list = self.navigationController.navigationBar.subviews;
        for (id obj in list) {
            if ([obj isKindOfClass:[UIImageView class]]) {
                UIImageView *imageView = (UIImageView *)obj;
                NSArray *list2 = imageView.subviews;
                for (id obj2 in list2) {
                    if ([obj2 isKindOfClass:[UIImageView class]]) {
                        UIImageView *imageView2 = (UIImageView *)obj2;
                        imageView2.hidden = YES;
                    }
                }
            }
        }
    }
    self.automaticallyAdjustsScrollViewInsets = NO;
}


- (void)createSubViews {
    self.loginView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    [self.view addSubview:_loginView];
    self.loginView.hidden = NO;
    
    self.logoutView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    [self.view addSubview:_logoutView];
    self.logoutView.hidden = YES;
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 49) style:UITableViewStylePlain];
    [self.loginView addSubview:_tableView];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    [self.tableView registerNib:[UINib nibWithNibName:@"YMMyListType1TableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"CellOfList1"];
    [self.tableView registerNib:[UINib nibWithNibName:@"YMMyListType2TableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"CellOfList2"];
    [self.tableView registerNib:[UINib nibWithNibName:@"YMMyListType3TableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"CellOfList3"];
    [self.tableView setTableFooterView:[[UIView alloc] init]];
    [self.tableView setSeparatorInset:UIEdgeInsetsZero];
    [self.tableView setLayoutMargins:UIEdgeInsetsZero];
    
    
    [self createHeaderView];
}

- (void)createHeaderView {
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 200)];
    self.tableView.tableHeaderView = headerView;
    headerView.backgroundColor = [UIColor grayColor];
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 400)];
    imageView.contentMode =  UIViewContentModeScaleAspectFill;
    imageView.center = headerView.center;
    headerView.clipsToBounds  = YES;
    [imageView setContentScaleFactor:[[UIScreen mainScreen] scale]];
    [imageView setImage:[UIImage imageNamed:@"2222.jpg"]];
    [headerView addSubview:imageView];
    
    
    UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
    UIVisualEffectView *visualView = [[UIVisualEffectView alloc] initWithEffect:blur];
    visualView.frame = imageView.bounds;
    [imageView addSubview:visualView];
    visualView.alpha = 1;
    
    UIImageView *imageViewOfUserView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, headerView.frame.size.height / 2, headerView.frame.size.height / 2)];
    [headerView addSubview:imageViewOfUserView];
    imageViewOfUserView.image = [UIImage imageNamed:@"2222.jpg"];
    imageViewOfUserView.center = headerView.center;
    imageViewOfUserView.layer.cornerRadius = headerView.frame.size.height / 2 / 2;
    imageViewOfUserView.layer.masksToBounds = YES;
    
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 4;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.row == 0) {
        YMMyListType1TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellOfList1"];
        [cell handleDataWithTitle:@"用户名" andContent:@"aaaaa"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else if (indexPath.row == 1) {
        YMMyListType1TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellOfList1"];
        [cell handleDataWithTitle:@"性别" andContent:@"男"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else if (indexPath.row == 2) {
        YMMyListType2TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellOfList2"];
        [cell handleDataWithContent:@"asdasdhsjakdhsajdhjkaskjdh"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else {
        YMMyListType3TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellOfList3"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 2) {
        return 100;
    }else {
        return 50;
    }
}

/** 解决tableView横线不是从头开始的问题 */
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
